/*
 * FunctionBoundaryCondistionforThermalResponse.C
 *
 *  Created on: Jan 17, 2022
 *      Author: liuxiao
 */

#include "libmesh/system.h"
#include "libmesh/radial_basis_interpolation.h"
#include<iostream>

#include "../../include/materials/FunctionBoundaryCondistionforThermalResponse.h"
#include "Function.h"
#include "libmesh/quadrature.h"
using std::cout;
using std::endl;
registerMooseObject("TrilobitaApp", FunctionBoundaryCondistionforThermalResponse);
template<>
InputParameters validParams<FunctionBoundaryCondistionforThermalResponse>()
{
	InputParameters params = validParams<Material>();

	params.addRequiredCoupledVar("wall_temperature_variable", "Coupled Wall Temperature");
	params.addParam<Real>("Pe_O2", 0.21, "partial pressure of O2 at boundary layer edge,1");
	params.addParam<Real>("Pe_N2", 0.79, "partial pressure of N2 at boundary layer edge,1");
	params.addParam<Real>("M_e", 0.029, " average molar mass of gas at boundary layer edge,kg/mol");
	params.addRequiredParam<FunctionName>("qc_function", "The function to compute cold wall heat flux.");
	params.addRequiredParam<FunctionName>("Pe_function", "The function to compute boundary edge pressure.");
	params.addRequiredParam<FunctionName>("hr_function", "The function to compute recovery enthalpy.");
	params.addRequiredParam<FunctionName>("Tw_function", "The function to compute wall temperature.");
	return params;
}

FunctionBoundaryCondistionforThermalResponse::FunctionBoundaryCondistionforThermalResponse(const InputParameters& parameters) :
	Material(parameters),
	_qc(declareProperty<Real>("coldwall_heatflux")),
	_qc_0K(declareProperty<Real>("heatflux_0K")),
	_hr(declareProperty<Real>("recovery_enthalpy")),
	_Pe(declareProperty<Real>("boundary_layer_edge_pressure")),
	_Pe_atm(declareProperty<Real>("Pe_atm")),
	_Pe_O2(declareProperty<Real>("Pe_O2")),
	_Pe_N2(declareProperty<Real>("Pe_N2")),
	_M_e(declareProperty<Real>("M_e")),
	_Tw(coupledValue("wall_temperature_variable")),
	_Pe_O2_p(getParam<Real>("Pe_O2")),
	_Pe_N2_p(getParam<Real>("Pe_N2")),
	_M_e_p(getParam<Real>("M_e")),
	_Tw_qc(declareProperty<Real>("Tw_for_coldwall_heatflux")),
	_qc_func(getFunction("qc_function")),
	_Pe_func(getFunction("Pe_function")),
	_hr_func(getFunction("hr_function")),
	_tw_func(getFunction("Tw_function"))

{
	
}



void FunctionBoundaryCondistionforThermalResponse::computeProperties()
{

	for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
	{
		_qc[_qp] = _qc_func.value(_t, _q_point[_qp]);
	//	std::cout << _qc[_qp] << std::endl;
		_Tw_qc[_qp] = _tw_func.value(_t, _q_point[_qp]);
		_hr[_qp] = _hr_func.value(_t, _q_point[_qp]);
		_qc_0K[_qp] = _qc[_qp];
		_Pe[_qp] = _Pe_func.value(_t, _q_point[_qp]);
		_Pe_atm[_qp] = _Pe[_qp] / 101325;
		_Pe_O2[_qp] = _Pe_atm[_qp] * _Pe_O2_p;
		_Pe_N2[_qp] = _Pe_atm[_qp] * _Pe_N2_p;
		_M_e[_qp] = _M_e_p;
	}
}



